package com.test1.demo.controller;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class HelloController {//@RequestMapping("/index")

    @RequestMapping("/")
    public String index(){
        //System.out.println("你好呀，spring boot，这是我的第一个idea项目");
        return "你好呀，spring boot，这是我的第一个idea项目";  //中文乱码问题
        //return "Hello,Spring boot! This is my first idea project.";
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ac){
        return args -> {

            System.out.println("由Spring Boot注册所有的 bean:");

            String[] beanNames = ac.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for(String beanName : beanNames)
                System.out.println(beanName);
        };  //注意这里的 return 语句块分号
    }
}
